package com.anyikang.volunteer.sos.volunteer.app.main;

import android.support.v4.app.Fragment;
import com.anyikang.volunteer.sos.volunteer.app.sos.SosListFragment;
import com.anyikang.volunteer.sos.volunteer.app.spot.SpotFragment;

/**
 * @author xw.gao
 * @version 2017/4/21
 * @git http://60.205.139.138:81/root/GSMServerAPP.git
 */
public class FragmentFactory {

    public static HomeFragment homeFragment = null;    //首页
    public static SosListFragment sosListFragment = null;  //呼救列表
    public static SpotFragment spotFragment = null;
    public static MineFragment mineFragment = null;


    /**
     * 根据底部导航的索引 获取对应的fragment的实例
     *
     * @param position
     * @return
     */
    public static Fragment getFragment(int position) {
        Fragment fragment = null;
        switch (position) {
            case 0:
                if (homeFragment == null) {
                    homeFragment = new HomeFragment();//首页
                }
                fragment = homeFragment;
                break;
            case 1:
                if (sosListFragment == null) {
                    sosListFragment = new SosListFragment();//群聊
                }
                fragment = sosListFragment;
                break;
            case 2:
                if (spotFragment == null) {
                    spotFragment = new SpotFragment();//记录
                }
                fragment = spotFragment;
                break;
            case 3:
                if (mineFragment == null) {
                    mineFragment = new MineFragment();//我的
                }
                fragment = mineFragment;
                break;
        }
        return fragment;
    }
}
